package dssd.acciones;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

import dssd.constantes.Constantes;
import dssd.modelo.Conductor;
import dssd.modelo.SolicitudAlta;
import dssd.modelo.Usuario;

public abstract class AbstractAccion extends ActionSupport implements SessionAware, ApplicationAware, ServletRequestAware {

	private static final long serialVersionUID = 2178998746537377787L;

	private HttpServletRequest request;
	protected static final Object CONDUCTOR = "conductor";
	protected static final String VIGENTE = "vigente";
	
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;		
	}

	public HttpServletRequest getRequest() {
		return request;
	}
	private Map<String, Object> session;

	@SuppressWarnings("unchecked")
	public void setSession(Map value) {
		this.session = value;
	}

	protected Usuario getUsuario() {
		return (Usuario) this.getSession().get(Constantes.USUARIO);
	}
	/**
	 * <p>
	 * Provide session context.
	 * </p>
	 * 
	 * @return session context
	 */
	public Map<String, Object> getSession() {
		return this.session;
	}
	private Map<String, Object> application;

	/**
	 * <p>
	 * Store a new application context.
	 * </p>
	 * 
	 * @param value
	 *            A Map representing application state
	 */
	@SuppressWarnings("unchecked")
	public void setApplication(Map value) {
		this.application = value;
	}

	/**
	 * <p>
	 * Provide application context.
	 * </p>
	 */
	public Map<String, Object> getApplication() {
		return this.application;
	}
protected void controlarSolicitud(Conductor conductor){
    if(conductor.getUltimaSolicitud()!=null){
    	if(conductor.getUltimaSolicitud().esDesaprovada()){
    		this.getSession().put("altaCartel", true);//cartel dar de alta
    	}else{
    		this.getSession().put("altaCartel", false);//sin cartel dar de alta
    		if(conductor.getUltimaSolicitud().getLicencia()==null){
    			this.getSession().put("alta", true);//alta
    			SolicitudAlta solicitudAlta=(SolicitudAlta) conductor.getUltimaSolicitud();
    			if(solicitudAlta.getExamenMedico().equalsIgnoreCase(Constantes.ADEUDA)){
    				this.getSession().put("adeuda", true);//adeuda examenMedico
    			}else{
    				this.getSession().put("adeuda", false);//no adeuda examenMedico
    			}
    		}else{
    			this.getSession().put("alta", false);//renovacion
    		}
    	}
    }else{//no tiene solicitud
    	this.getSession().put("altaCartel", true);//cartel dar de alta
    }	
}
}